<%layout("/common/_layout.html"){ %>
<%#ajax userTable:{%>
<div class="am-cf am-padding">
  <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg">系统管理</strong>
    /
    <small>知识库管理</small>
  </div>
</div>

<div class="am-g">
  <div class="am-u-sm-12">
    <form class="am-form" id="list-form" action="${base}/knowledgeBase/list" method="post">
      <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
      <table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;">
        <tbody>
          <tr>
            <th class="am-text-middle">资费编码</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="code" class="am-form-field am-input-sm" value="${code!}" />
              </div>
            </td>

            <th class="am-text-middle">名称</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="name" class="am-form-field am-input-sm" value="${name!}" />
              </div>
            </td>
          </tr>
          
          <tr>
            <th class="am-text-middle">类型</th>
            <td>              
               <div class="am-u-sm-10">
                <select data-am-selected="{btnSize:'sm',maxHeight: 300}" name="type_id"  id="type_id">
                  <%for(type in typeList){%>
                  <option value="${type.value}" <%if(type_id==type.value){%>
                      selected
                      <%}%>>${type.key}</option>
                <%}%></select>
              </div>
            </td>
            <th class="am-text-middle">可见地市</th>
            <td>            
              <div class="am-u-sm-10">
                <select data-am-selected="{btnSize:'sm',maxHeight: 300}" name="city_id" id="city_id">
                  <%for(city in cityList){%>
                  <option value="${city.value}" <%if(city_id==city.value){%>
                      selected
                      <%}%>>${city.key}</option>
                <%}%></select>
              </div>
            </td>
          </tr>

          <tr>
            <td colspan="4">
              <div align='right'>
                <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary" id="submit-btn">搜索</button>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </form>
  </div>

  <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
    <div class="am-btn-toolbar" style="padding-left:.5rem;">
      <div class="am-btn-group am-btn-group-xs am-fl">
          <button type="button "id="bt_add" class="am-btn am-btn-default"
                  onclick="location.href='${base}/knowledgeBase/add'"
          >新增</button>
        <%if(so.hasPermission("KB_UPLOAD")) {%>
        <div class="am-btn-group am-btn-group-xs am-form-file">
          <button type="button" id="bt_import" class="am-btn am-btn-default">
            <span class="am-icon-archive"></span>
            导入
          </button>
          <input id="doc-form-file" type="file" name="import" onChange="ajaxUploadFile('doc-form-file','${base}/knowledgeBase/upload')" multiple></div>
        <%}%>       
        <%if(so.hasPermission("KB_EXPORT")) {%>
        <button type="button" id="export-btn" class="am-btn am-btn-default common-export">
          <span class="am-icon-save"></span>
          导出
        </button>
        <%}%>
        <button type="button" class="am-btn am-btn-default common-export" onClick="location.href='${base}/knowledgeBase/template'">
            <span class="am-icon-download"></span>
            模板
          </a>
        </button>             
        <%if(so.hasPermission("KB_DELETE")) {%>
        <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteAll('${base}/knowledgeBase/delete')">
          <span class="am-icon-trash-o"></span>
          删除
        </button>
        <%}%>
      <div class="am-text-xs am-fl am-margin-top-xs" style="color:red">&nbsp&nbsp*省级知识库导入时，请Excel中启用宏，否则无法选择可见地市</div>
    </div>  
  </div>
  <div class="am-g" id="download" style="display:none">      
    <div align='center'>
      <a id="downloadlink" href="#">导出成功，点击下载</a>
    </div>      
  </div>    
</div>

<div class="am-g">
<div class="am-u-sm-12">

  <div class="am-scrollable-horizontal">
    <table class="am-table am-table-striped am-table-hover table-main">
      <thead>
        <tr class="am-text-nowrap">
          <th class="table-check">
            <input type="checkbox"  id="allCheck"/>
          </th>
          <th class="table-title">名称</th>
          <th class="table-title">类型</th>
          <th class="table-title">资费编码</th>
          <th class="table-title">可见地市</th>
          <th class="table-title">发布者</th>
          <th class="table-title">浏览量</th>
          <th class="table-title">更新时间</th>
          <th class="table-title">设置</th>
          <th class="table-title">操作</th>
        </tr>
      </thead>
      <tbody>
        <%for(list in pager.list!){%>
        <tr>
          <td>
            <input type="checkbox" name="ids" value="${list.id}"></td>
          <td>${list.name}</td>
          <td class="am-text-nowrap">${list.type}</td>
          <td>${list.code}</td>
          <td>${list.city_zone}</td>
          <td>${list.created}</td>
          <td>${list.pv_count}</td>
          <td class="am-text-nowrap">${list.modi_date,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
          <td><%if (list.enabled==1){%>
            有效
            <%}else{%>
            无效
            <%}%></td>
          <td>
            <div class="am-btn-toolbar">
              <div class="am-btn-group am-btn-group-xs">    
                <%if(so.hasPermission("KB_EDIT")) {%>                
                  <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="location.href='${base}/knowledgeBase/edit?id=${list.id}'"><span class="am-icon-pencil-square-o"></span>修改</button>
                <%}%>
              </div>
            </div>
          </td>
        </tr>
        <%}%></tbody>
    </table>
  </div>

  <div class="am-cf">
    <!-- 分页 -->
    <%if (pager.list.~size >
    0){%>
    <div class="am-fr">
      <% include("/admin/common_pager.tpl"){}%></div>
    <%}else{%>
    <div class="am-kai">
      <h3>没有找到任何记录!</h3>
    </div>
    <%}%></div>

</div>
</div>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="modal">
<div class="am-modal-dialog">
  <div class="am-modal-hd">
    <i class="am-icon-refresh am-icon-spin"></i>
    <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
  </div>
  <div class="am-modal-bd">正在处理，请稍等...</div>
</div>
</div>

<script type="text/javascript">
    $(function(){
      var keywordsObj = {};      
      $("#submit-btn").on("click",function(){
        setKeyWords();
        $("#list-form").submit();
      });
      $("#export-btn").on("click", function () {
            $('#download').hide();
            //loading层
            var index = parent.layer.load(0, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            setKeyWords();            
            //$("#list-form").submit();
            var formParam = $("#list-form").serialize();//序列化表格内容为字符串
            $.ajax({
                type: 'post',
                url: '${base}/knowledgeBase/export',
                data: formParam,
                success: function (data) {
                    console.log(data);
                    if (data.status == 1) {
                        $('#downloadlink').text(data.message);
                        $('#downloadlink').attr('href', data.url);
                        $('#download').show();
                    } else {
                        $('#downloadlink').text(data.message);
                        $('#download').show();
                    }
                    parent.layer.close(index);
                },
                error: function () {
                    parent.layer.close(index);
                }
            });
        });
      function setKeyWords(){
        if($("#name").val())
          keywordsObj.name = $("#name").val();
        if($("#code").val())
          keywordsObj.code = $("#code").val();
        if($("#type_id").val())
          keywordsObj.type_id = $("#type_id").val();
        if($("#city_id").val())
          keywordsObj.city_id = $("#city_id").val();
        console.log("keywords = "+ keywords);        
        var keywords = "";
        if(!$.isEmptyObject(keywordsObj)){
          keywords = JSON.stringify(keywordsObj);
        }
        console.log("keywords = "+ keywords);
        $("#keywords").val(keywords);
      }
    });
  </script>
<%}%>
<%}%>
